package cn.kimoon.dau_android;

import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import cn.kimoon.dau_android.Model.ModelCollectorInfo;
import cn.kimoon.dau_android.Model.ModelEngineDetail;

/**
 * Created by xiangdong on 2016/11/23.
 */

public class MonitorFragmentPagerAdapter extends FragmentPagerAdapter {
    private HumitureFragment humitureFragment;
    private WarningFragment warningFragment;
    private ElectricityFragment electricityFragment;
    private ControlFragment controlFragment;

    public MonitorFragmentPagerAdapter(FragmentManager fm) {
        super(fm);

        humitureFragment = new HumitureFragment();
        warningFragment = new WarningFragment();
        electricityFragment = new ElectricityFragment();
        controlFragment = new ControlFragment();
    }

//    public MonitorFragmentPagerAdapter(FragmentManager fm, ModelCollectorInfo info) {
//        super(fm);
//
//        System.out.println("适配器读取值" + info.temperature_secure_line_upper);
//        humitureFragment = new HumitureFragment();
//        humitureFragment.setInfo(info);
//
//        warningFragment = new WarningFragment();
//        warningFragment.setContact(info.contact);
//
//        electricityFragment = new ElectricityFragment();
//        electricityFragment.setPower(info.power_consumpsion);
//
//        controlFragment = new ControlFragment();
//        controlFragment.setInfo(info);
//    }

    public void updateLogicData(ModelCollectorInfo info) {
        humitureFragment.setInfo(info);
        warningFragment.setContact(info.contact);
        electricityFragment.setPower(info.power_consumpsion);
        controlFragment.setInfo(info);
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        return super.instantiateItem(container, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        System.out.println("position destroy" + position);
        super.destroyItem(container, position, object);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = humitureFragment;
                break;
            case 1:
                fragment = warningFragment;
                break;
            case 2:
                fragment = electricityFragment;
                break;
            case 3:
                fragment = controlFragment;
                break;
        }
        return fragment;
    }
}
